package com.hujiang.basic.search.model;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.Collection;

@Data
@EqualsAndHashCode(callSuper = true)
public class HJBulkResponse extends HJEsResponse {

    private static final long serialVersionUID = 1L;

    private int successCnt;

    private int failureCnt;

    private int total;

    private long tookInMillis;

    private Collection<HJBulkResponseItem> successes = new ArrayList<>();

    private Collection<HJBulkResponseItem> failures = new ArrayList<>();

    public void addItem(HJBulkResponseItem item) {
        if (item.isFailed()) {
            addFailure(item);
        }
        else {
            addSuccess(item);
        }
    }

    private void addSuccess(HJBulkResponseItem item) {
        successCnt = successCnt + 1;
        total = total + 1;
        successes.add(item);
    }

    private void addFailure(HJBulkResponseItem item) {
        failureCnt = failureCnt + 1;
        total = total + 1;
        failures.add(item);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        } else if (null!=obj && this.getClass() != obj.getClass()) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return this.hashCode();
    }
}
